<?php namespace web\admin\controller;
class Type extends Common
{
    private $db;
    public function __construct(){
        parent::__construct();
        $this->db = new \system\model\Type();
    }
    //类型首页
    public function index(){
        $data = $this->db->getAll();
        //p($data);die;
        View::with('data',$data)->make();
    }

   //类型添加
    public function add()
    {
        if (IS_POST) {

            if($this->db->store()){
                message('添加成功', U('index'), 'success');
            }
            message($this->db->getError(), 'back', 'error');
        }
        View::make();

    }
    //类型编辑
    public function edit(){
        if(IS_POST){
            if($this->db->edit()){
                message('编辑成功',U('index'),'success');
            }
                message($this->db->getError(),'','error');
        }
        $tid = q('get.tid',0,intval);
        //获得旧数据
        $oldData = $this->db->where('tid',$tid)->first();
        View::with('oldData',$oldData)->make();
    }
    //类型删除
    public function del(){
        $tid = q('get.tid',0,intval);
        $this->db->where('tid',$tid)->delete();
        message('删除成功',U('index'),'success');
    }
}